package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 质量检查要求枚举
 *
 * <p>定义成绩质量检查过程中的各种检查要求，包括完整性检查、准确性检查、规范性检查等。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum QualityCheckRequirement implements BaseEnum {

    /**
     * 不需要质量检查
     */
    NONE("NONE", "不需要"),

    /**
     * 可选质量检查
     */
    OPTIONAL("OPTIONAL", "可选"),

    /**
     * 建议质量检查
     */
    RECOMMENDED("RECOMMENDED", "建议"),

    /**
     * 必须质量检查
     */
    REQUIRED("REQUIRED", "必须"),

    /**
     * 强制质量检查
     */
    MANDATORY("MANDATORY", "强制"),

    /**
     * 双重质量检查
     */
    DOUBLE_CHECK("DOUBLE_CHECK", "双重检查");

    private final String code;
    private final String description;

    QualityCheckRequirement(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static QualityCheckRequirement fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Quality check requirement code cannot be null or empty");
        }

        for (QualityCheckRequirement requirement : values()) {
            if (requirement.getCode().equals(code)) {
                return requirement;
            }
        }
        throw new IllegalArgumentException("Unknown quality check requirement code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static QualityCheckRequirement fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Quality check requirement description cannot be null or empty");
        }

        for (QualityCheckRequirement requirement : values()) {
            if (requirement.getDescription().equals(description)) {
                return requirement;
            }
        }
        throw new IllegalArgumentException("Unknown quality check requirement description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}